<!-- 在这个文件对每个tab对应的列表进行渲染 -->
<template>
	<view class="paryorder-content">
		<!-- 这里设置了z-paging加载时禁止自动调用reload方法，自行控制何时reload（懒加载）-->
		<!--  :enable-back-to-top="currentIndex===tabIndex" 在微信小程序上可以多加这一句，因为默认是允许点击返回顶部的，但是这个页面有多个scroll-view，会全部返回顶部，所以需要控制是当前index才允许点击返回顶部 -->
		<z-paging ref="paging" v-model="dataList" @query="queryList" :fixed="false" :auto="true">
			<template #top>
				<view class="" >
					<fui-nav-bar title="订单查询" background="#ffbb1a" isFixed isOccupy  @leftClick="pageBack"></fui-nav-bar>
					<view class="u-p-35 stat-container" style="background-color: #FFBB1A;"  >
						<image :src="shopInfo.buyerLogoUrl?shopInfo.buyerLogoUrl:defaultLogo" mode="" class="shop-image u-m-t-10 u-m-b-28" ></image>
						<view class="u-text-center u-font-32 u-m-b-40" style="font-weight: 500; ">{{shopInfo.buyerName}}</view>
						<view class="u-flex">
							<view class="u-m-b-40" style="width: 50%;">
								<view class="u-text-center u-m-b-22">订单量（单）</view>
								<view class="u-text-center u-font-30" style="font-weight: 500;">{{shopInfo.tradeCount}}</view>
							</view>
							<view class="u-m-b-40"  style="width: 50%;">
								<view class="u-text-center u-m-b-22">交易额（元）</view>
								<view class="u-text-center u-font-30" style="font-weight: 500;">{{shopInfo.totalAmount}}</view>
							</view>
							
						</view>
						<view class="u-flex">
							<view class="u-flex u-p-20 u-m-r-20 date-box"  @click="startShow = true">
								<view class="" style="color: #999;">{{startDate}}</view>
								<u-icon name="play-right-fill" color="#999"></u-icon>
							</view>
							<view class="u-flex u-p-20 date-box"  @click="endShow = true">
								<view class="" style="color: #999;">{{endDate}}</view>
								<u-icon name="play-right-fill" color="#999" ></u-icon>
							</view>
						</view>
					</view>
				</view>
			</template>
			<!-- 如果希望其他view跟着页面滚动，可以放在z-paging标签内 -->
			<view class="payorder-container" v-for="(item,index) in dataList" :key="index" @click="goStatDetails(item.tradeId)">
				<view class="payorder-section">
					<view class="section-list">
						<view class="section-item">
							<view class="u-flex u-row-between">
								<view class="u-flex u-m-b-10">
									<view :class="['u-flex', 'u-row-center','u-m-r-20', 'u-col-center','pay-status',{'pay-status-active':item.state>0}]">
										<u-icon name="order" class="u-m-r-10 u-m-b-4" :color="item.state>0?'#FFBB1A':'#999'" size="30"></u-icon>
										<text class="u-font-16" :style="{'color':item.state>0?'#FFBB1A':'#999'}"> {{orderState[item.state]}}</text>
									</view>
									<view :class="['u-flex', 'u-row-center','u-m-r-20', 'u-col-center','pay-status',{'pay-status-active':item.isPaid}]">
										<img :src="item.isPaid?'static/xiaoshou/zhifudan.png':'static/xiaoshou/zhifuda.png'" style="width: 26rpx;height: 26rpx;" alt="">
										<text class="u-font-16 u-m-l-10" :style="{'color':item.isPaid?'#FFBB1A':'#999'}"> {{item.isPaid?'已付款':'未付款'}}</text>
									</view>
								</view>
								<view class="">
									<img :src="item.paymentMethod?payIcon[item.paymentMethod]:payIcon['null']" style="width: 48rpx;height: 48rpx;" alt="">
								</view>
							</view>
							<view class="section-item-count u-m-b-10 u-flex u-col-center" >
								订单编号 <text class="u-m-l-20 u-font-32" style="color: #333;font-weight: 500;">  {{item.tradeNo}}  </text>
							</view>
							<view class="u-flex">
								<view class="section-item-count u-m-b-10 u-m-r-30 u-flex u-col-center" >
									商品数量 <text class="u-m-l-20 u-font-32" style="color: #333;font-weight: 500;">  {{item.itemsCount}}  </text>
								</view>
								<view class="section-item-count u-m-b-10 u-flex u-col-center" >
									订单金额 <text class="u-m-l-20 u-font-32" style="color: #333;font-weight: 500;">  ￥{{item.tradeAmount}}  </text>
								</view>
							</view>
							<view class="u-flex u-row-between">
								<view class="section-item-count u-m-b-10 u-flex u-col-center" >
									下单时间<text class="u-m-l-20 u-font-16" style="color: #999;">  {{$fui.dateFormatter(item.createdTime, 'y-m-d h:i')}}  </text>
								</view>
								<view class="section-item-count u-m-b-10 u-flex u-col-center" >
									实付金额 <text class="u-m-l-20 u-font-32" style="color: #333;font-weight: 500;">  ￥{{item.actualAmount}}  </text>
								</view>
							</view>
						</view>
					</view>
					
				</view>
			</view>
			 
		</z-paging>
		<u-calendar v-model="startShow" :mode="'date'" @change="startDateChange">
			<view slot="tooltip">
				<view class="title  u-text-center u-m-t-30">
					请选择开始日期
				</view>
			</view>
		</u-calendar>
		<u-calendar v-model="endShow" :mode="'date'" @change="endDateChange">
			<view slot="tooltip">
				<view class="title u-text-center u-m-t-30">
					请选择结束日期
				</view>
			</view>
		</u-calendar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//v-model绑定的这个变量不要在分页请求结束中自己赋值！！！
				dataList: [],
				searchText:'',
				startDate:'起始日期',
				endDate:'结束日期',
				shopInfo:{},
				startShow:false,
				endShow:false,
				payIcon:{
					"null":'static/payment/weixuanze.png',
					0:'static/payment/weixin.png',
					7:'static/payment/weixin.png',
					1:'static/payment/zhifubao.png',
					11:'static/payment/zhifubao.png',
					3:'static/payment/xianxiazhifu.png',
					4:'static/payment/xianxiazhifu.png',
					10:'static/payment/gonghang.png',
				},
				orderState:['待确认','待发货','待收货','待评价','已完成','已取消',]
			}
		},
		created(){
			let nowDate = this.$fui.dateFormatter(new Date(), 'y-m-d');
			this.startDate = nowDate.substring(0,nowDate.length-2).concat('01');
			this.endDate = this.$fui.dateFormatter(new Date(), 'y-m-d');
		},
		onLoad(options) {
			this.shopId = options.id
		},
		methods: {
			startDateChange(val){
				console.log(val);
				this.startDate = val.result;
				this.reloadFn();
			},
			endDateChange(val){
				console.log(val);
				this.endDate = val.result;
				this.reloadFn();
			},
			reloadFn(){
				this.$refs.paging.reload();
			},
			goStatDetails(id){
				this.$mRouter.push({
					route: '/pages/sale/order/xiangqing?id='+id 
				})
			},
			async queryList(pageNo, pageSize) {
				//组件加载时会自动触发此方法，因此默认页面加载时会自动触发，无需手动调用
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				//模拟请求服务器获取分页数据，请替换成自己的网络请求
				const params = {
					pageIndex: pageNo,
					pageSize: pageSize,
					BuyerId:this.shopId,
					StartDate:this.startDate,
					EndDate:this.endDate+' 23:59:59',
				}
				if(this.searchText!==''){
					params.keywords = this.searchText;
				}
				uni.showLoading({
					title: 'loading...',
					mask: false
				});
				const res = await this.$newHttp.get('api/SalesReport/GetTransactionRecordsWitDesignatedBuyer', { params: params } );
				uni.hideLoading({
					title: 'loading...'
				})
				if(res.code === 200){
					this.shopInfo = res.data;
					this.$refs.paging.complete(res.data.pageDatas.list);
				}else{
					this.$refs.paging.complete(false);
				}
			},
			itemClick(item) {
				console.log('点击了', item.title);
				this.$mRouter.push({ 
					route: '/pages/sale/payorder/createPayOrder?shop='+item.id,
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	/* 注意:父节点需要固定高度，z-paging的height:100%才会生效 */
	.paryorder-content {
		height: 100%;
		
	}
	.stat-container{
		.shop-image{
			width:120rpx;
			height: 120rpx;
			border-radius: 50%;
			display: block;
			margin: 0 auto;
		}
		.date-box{
			flex:1;
			background-color: #fff;
			height: 80rpx;
			border-radius: 10rpx;	
			justify-content: space-between;
			align-items: center;
		}
	}
	.payorder-container{
		background-color: #fff;
		box-sizing: border-box;
		padding: 0 30rpx;
		.payorder-header{
			display: flex;
			justify-content: space-between;
		}
		.payorder-section{
			display: flex;
			align-items: center;
			box-sizing: border-box;
			padding: 35rpx 0;
			margin-bottom: 20rpx;
			.section-image{
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
				margin-right: 32rpx;
			}
			.section-list{
				flex: 1;
				margin-left: 20rpx;
				
				.section-item{
					width: 100%;
					.pay-status{
						border:1px solid #999;
						box-sizing: border-box;
						padding: 8rpx 18rpx 8rpx 10rpx;
						border-radius: 30rpx;
						color: #999;
					}
					.pay-status-active{
						border-color: #FFBB1A !important;
						color: #FFBB1A;
					}
					.section-item-name{
						font-size: 32rpx;
						font-weight: 500;
						margin-bottom: 10rpx;
					}
					.section-item-count{
						font-size: 24rpx;
						color: #999;
					}
					.section-btn{
						width: 160rpx;
						margin-left: 10rpx;
						height:70rpx;
						border-radius: 35rpx;
						border: 1rpx solid #FFBB1A;
						color: #FFBB1A;
						text-align: center;
						line-height: 70rpx;
					}
					.section-btn-disabled{
						border-color:#999999;
						color: #999999;
					}
				}
			}
			
		}
		
	}


</style>
